<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="服务名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入服务名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="汇聚来源" prop="convergeFrom">
        <el-select v-model="queryParams.convergeFrom" placeholder="请选择汇聚来源" clearable>
          <el-option
            v-for="dict in dict.type.tgis_converge_from"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="数据类型" prop="dataType">
        <el-select v-model="queryParams.dataType" placeholder="请选择数据类型" clearable>
          <el-option
            v-for="dict in dict.type.tgis_data_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="启用状态" prop="isStart">
        <el-select v-model="queryParams.isStart" placeholder="启用状态" clearable>
          <el-option
            v-for="dict in dict.type.tgis_is_start"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="注册状态" prop="registerStatus">
        <el-select v-model="queryParams.registerStatus" placeholder="注册状态" clearable>
          <el-option
            v-for="dict in dict.type.tgis_register_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="代理地址" prop="proxyUrl">
        <el-input
          v-model="queryParams.proxyUrl"
          placeholder="请输入代理地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['tgis:allServer:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['tgis:allServer:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['tgis:allServer:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['tgis:allServer:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="allServerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="服务名称" width="200" align="center" prop="name" />
      <el-table-column label="汇聚来源" align="center" prop="convergeFrom">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tgis_converge_from" :value="scope.row.convergeFrom"/>
        </template>
      </el-table-column>
      <el-table-column label="数据类型" align="center" prop="dataType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tgis_data_type" :value="scope.row.dataType"/>
        </template>
      </el-table-column>
      <el-table-column label="服务类型" align="center" prop="serverType" />
      <el-table-column label="代理地址" :show-overflow-tooltip="true" prop="proxyUrl" />
      <el-table-column label="接口授权标识" align="center" prop="authStr" />
      <el-table-column label="是否可进行在线状态检测" align="center" prop="canCheck" />
      <el-table-column label="在线状态检测示例url" :show-overflow-tooltip="true" prop="demoRealUrl" />
      <el-table-column label="请求返回状态值" align="center" prop="onlineStatus" />
      <el-table-column label="地图状态" align="center" prop="registerStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tgis_register_status" :value="scope.row.registerStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="是否启用" align="center" prop="isStart">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tgis_is_start" :value="scope.row.isStart"/>
        </template>
      </el-table-column>
      <el-table-column label="所属目录" align="center" prop="catalogName" />
      <!-- <el-table-column label="描述" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['tgis:allServer:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['tgis:allServer:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改服务基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="服务名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入服务名称" />
        </el-form-item>
        <el-form-item label="汇聚来源" prop="convergeFrom">
          <el-select v-model="form.convergeFrom" placeholder="请选择汇聚来源">
            <el-option
              v-for="dict in dict.type.tgis_converge_from"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据类型" prop="dataType">
          <el-select v-model="form.dataType" placeholder="请选择数据类型">
            <el-option
              v-for="dict in dict.type.tgis_data_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="服务类型" prop="serverType">
          <el-input v-model="form.serverType" placeholder="请输入服务类型" />
        </el-form-item>
        <el-form-item label="服务数据来源,市CIM平台合并" prop="providerFrom">
          <el-input v-model="form.providerFrom" placeholder="请输入服务数据来源,市CIM平台合并" />
        </el-form-item>
        <el-form-item label="服务数据来源,市CIM平台拆分" prop="provider">
          <el-input v-model="form.provider" placeholder="请输入服务数据来源,市CIM平台拆分" />
        </el-form-item>
        <el-form-item label="数据归类" prop="dataTopic">
          <el-input v-model="form.dataTopic" placeholder="请输入数据归类" />
        </el-form-item>
        <el-form-item label="代理地址" prop="proxyUrl">
          <el-input v-model="form.proxyUrl" placeholder="请输入代理地址" />
        </el-form-item>
        <el-form-item label="接口授权标识" prop="authStr">
          <el-input v-model="form.authStr" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="图层名称" prop="layerName">
          <el-input v-model="form.layerName" placeholder="请输入图层名称" />
        </el-form-item>
        <el-form-item label="2D-sdk" prop="twoDimensional">
          <el-input v-model="form.twoDimensional" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="3D-sdk" prop="threeDimensional">
          <el-input v-model="form.threeDimensional" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="在线状态检测示例url" prop="demoRealUrl">
          <el-input v-model="form.demoRealUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="服务缩略图" prop="imageId">
          <el-input v-model="form.imageId" placeholder="请输入服务缩略图" />
        </el-form-item>
        <el-form-item label="坐标系" prop="coordsInfo">
          <el-input v-model="form.coordsInfo" placeholder="请输入坐标系" />
        </el-form-item>
        <el-form-item label="中心点x" prop="focusX">
          <el-input v-model="form.focusX" placeholder="请输入中心点x" />
        </el-form-item>
        <el-form-item label="中心点y" prop="focusY">
          <el-input v-model="form.focusY" placeholder="请输入中心点y" />
        </el-form-item>
        <el-form-item label="地图范围-左下角x" prop="leftX">
          <el-input v-model="form.leftX" placeholder="请输入地图范围-左下角x" />
        </el-form-item>
        <el-form-item label="地图范围-左下角y" prop="leftY">
          <el-input v-model="form.leftY" placeholder="请输入地图范围-左下角y" />
        </el-form-item>
        <el-form-item label="地图范围-右下角x" prop="rightX">
          <el-input v-model="form.rightX" placeholder="请输入地图范围-右下角x" />
        </el-form-item>
        <el-form-item label="地图范围-右下角y" prop="rightY">
          <el-input v-model="form.rightY" placeholder="请输入地图范围-右下角y" />
        </el-form-item>
        <el-form-item label="采集时间" prop="acquisitionTime">
          <el-input v-model="form.acquisitionTime" placeholder="请输入采集时间" />
        </el-form-item>
        <el-form-item label="更新频率" prop="updateFrequency">
          <el-input v-model="form.updateFrequency" placeholder="请输入更新频率" />
        </el-form-item>
        <el-form-item label="摘要" prop="digest">
          <el-input v-model="form.digest" placeholder="请输入摘要" />
        </el-form-item>
        <el-form-item label="描述" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAllServer, getAllServer, delAllServer, addAllServer, updateAllServer } from "@/api/tgis/allServer";

export default {
  name: "AllServer",
  dicts: ['tgis_is_start','tgis_data_type', 'tgis_converge_from','tgis_register_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 服务基础信息表格数据
      allServerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        convergeFrom: null,
        dataType: null,
        proxyUrl: null,
        demoRealUrl: null,
        registerStatus: null,
        isStart: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "服务名称不能为空", trigger: "blur" }
        ],
        isDelete: [
          { required: true, message: "删除标记:0-正常,1-已删除不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询服务基础信息列表 */
    getList() {
      this.loading = true;
      listAllServer(this.queryParams).then(response => {
        this.allServerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        convergeFrom: null,
        dataType: null,
        serverType: null,
        providerFrom: null,
        provider: null,
        dataTopic: null,
        proxyUrl: null,
        authStr: null,
        imageryProviderType: null,
        layerName: null,
        twoDimensional: null,
        threeDimensional: null,
        isPictureShow: null,
        canCheck: null,
        demoRealUrl: null,
        onlineStatus: null,
        registerStatus: [],
        imageId: null,
        isStart: null,
        coordsInfo: null,
        focusX: null,
        focusY: null,
        leftX: null,
        leftY: null,
        rightX: null,
        rightY: null,
        acquisitionTime: null,
        updateFrequency: null,
        digest: null,
        filePath: null,
        fileName: null,
        fileSize: null,
        fileType: null,
        analysisStatus: null,
        fileDatasetName: null,
        fileDatasetType: null,
        iserverWorkspaceName: null,
        iserverDbName: null,
        dbType: null,
        dbIp: null,
        dbPort: null,
        dbName: null,
        dbUserName: null,
        dbPassword: null,
        auditBy: null,
        auditOpinion: null,
        auditTime: null,
        submitTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        isDelete: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加服务基础信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAllServer(id).then(response => {
        this.form = response.data;
        // this.form.registerStatus = this.form.registerStatus.split(",");
        this.open = true;
        this.title = "修改服务基础信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // this.form.registerStatus = this.form.registerStatus.join(",");
          if (this.form.id != null) {
            updateAllServer(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAllServer(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除服务基础信息编号为"' + ids + '"的数据项？').then(function() {
        return delAllServer(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('tgis/allServer/export', {
        ...this.queryParams
      }, `allServer_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
